
package todolist.logic.parser;

import todolist.logic.CommandType;
import todolist.personalization.CommandCustomizer;

/**
 * Parser of Command to be executed.
 * @author Ivan
 */
public class CommandParser {
	
	private GenericParser _objGP;
	
	public CommandParser() {
		_objGP = new GenericParser();
	}

	/**
	 * Tries to parse a String containing name of Command.
	 * Command Type if found, or null otherwise, returned.
	 */
	public CommandType parseCommandType(String pstrInput) {
		// no-match conditions
		if (pstrInput == null)
			return null;
		pstrInput = pstrInput.trim();
		if (pstrInput.length() == 0)
			return null;
		// parse input
		if (_objGP.findMatch(CommandCustomizer.getInstance().getInputAddCommand(), pstrInput) != null)
			return CommandType.COMMAND_ADD;
		if (_objGP.findMatch(CommandCustomizer.getInstance().getInputEditCommand(), pstrInput) != null)
			return CommandType.COMMAND_EDIT;
		if (_objGP.findMatch(CommandCustomizer.getInstance().getInputDeleteCommand(), pstrInput) != null)
			return CommandType.COMMAND_DELETE;
		if (_objGP.findMatch(CommandCustomizer.getInstance().getInputDetailsCommand(), pstrInput) != null)
			return CommandType.COMMAND_DETAILS;
		if (_objGP.findMatch(CommandCustomizer.getInstance().getInputListCommand(), pstrInput) != null)
			return CommandType.COMMAND_LIST;
		if (_objGP.findMatch(CommandCustomizer.getInstance().getInputSearchCommand(), pstrInput) != null)
			return CommandType.COMMAND_SEARCH;
		if (_objGP.findMatch(CommandCustomizer.getInstance().getInputSortCommand(), pstrInput) != null)
			return CommandType.COMMAND_SORT;
		return null; // all phrases do not match
	}
	
}
